package fr.vod.ihm.adapter;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.VideoView;

public class MyVideoView extends VideoView {

    private PlayPauseListener mListener;
    private SeekListener sListener;

    public MyVideoView(Context context) {
        super(context);
    }

    public MyVideoView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyVideoView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    
    
    public void setPlayPauseListener(PlayPauseListener listener) {
        mListener = listener;
    }
    
    public void setSeekListener(SeekListener listner){
    	sListener=listner;
    }
    
    @Override
    public void pause() {
        super.pause();
        if (mListener != null) {
            mListener.onPause();
        }
    }

    @Override
    public void start() {
        super.start();
        if (mListener != null) {
            mListener.onPlay();
        }
    }

    @Override
    public void seekTo(int pos) {
        boolean ffwdrwd = false;
        if (super.getCurrentPosition() <= pos)
            ffwdrwd = false;
        else
            ffwdrwd = true;
        if (sListener != null) {
            sListener.onSeekTo(ffwdrwd);
        }
        super.seekTo(pos);
    }
    
    public interface PlayPauseListener {
        void onPlay();
        void onPause();
    }
    public interface SeekListener {
        void onSeekTo(boolean ffwdrwd);
    }


	public void startFromHandler() {
		super.start();
	}

	public void pauseFromHandler() {
		super.pause();
	}
	public void seekToFromHandler(int msec){
		super.seekTo(msec);
	}

}
